#include "widget.h"
#include "ui_widget.h"

#include <QKeyEvent>
#include <QtDebug>
#include <QLabel>
#include <QTimer>
#include <QPushButton>
#include <QDateTime>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::moveEvent(QMoveEvent *event)
{
    QPoint newPos = event->pos();
    QString moveInfo = QString("窗口移动到: x=%1, y=%2").arg(newPos.x()).arg(newPos.y());
    qDebug() << moveInfo;
}

void Widget::resizeEvent(QResizeEvent *event)
{
    QSize newSize = event->size();
    QString resizeInfo = QString("窗口大小调整为: 宽=%1, 高=%2").arg(newSize.width()).arg(newSize.height());
    qDebug() << resizeInfo;
}



//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    QTimer* timer = new QTimer(this);

//    connect(ui->pushButton,&QPushButton::clicked,[=](){
//        timer->start(1000);
//    });

//    connect(ui->pushButton_2,&QPushButton::clicked,[=](){
//        timer->stop();
//    });

//    connect(timer,&QTimer::timeout,this,&Widget::timeUpdate);
//}

//Widget::~Widget()
//{
//    delete ui;
//}

//void Widget::timeUpdate()
//{
//    QString str = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
//    ui->label->setText(str);
//}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    QTimer* timer = new QTimer(this);

//    connect(ui->pushButton,&QPushButton::clicked,[=](){
//        timer->start(1000);
//    });

//    connect(ui->pushButton_2,&QPushButton::clicked,[=](){
//        timer->stop();
//    });

//    connect(timer,&QTimer::timeout,[=](){
//        static int num = 1;
//        ui->label->setText(QString::number(num++));
//    });

//}

//Widget::~Widget()
//{
//    delete ui;
//}


//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);
//    //开启定时器
//    //timer1、timer2为两个整型变量
//    timer1 = startTimer(1000);
//    timer2 = startTimer(2000);
//}

//Widget::~Widget()
//{
//    delete ui;
//}

//void Widget::timerEvent(QTimerEvent *ev)
//{
//    if(ev->timerId() == timer1)
//    {
//        static int num1 = 1;
//        ui->label->setText(QString::number(num1++));
//    }
//    if(ev->timerId() == timer2)
//    {
//        static int num2 = 1;
//        ui->label_2->setText(QString::number(num2++));
//    }
//}

//Widget::Widget(QWidget *parent)
//    : QWidget(parent)
//    , ui(new Ui::Widget)
//{
//    ui->setupUi(this);

////    MyLabel* label = new MyLabel("这是一段字体",this);
////    label->setFont(QFont("Arial", 20)); // 设置初始字体
////    label->setAlignment(Qt::AlignCenter); // 设置文字居中
////    label->resize(400, 300); // 设置 QLabel 大小
////    label->show();
//}

//Widget::~Widget()
//{
//    delete ui;
//}

//void Widget::mousePressEvent(QMouseEvent *event)
//{
//    if(event->button() == Qt::LeftButton)
//    {
//        qDebug() << "鼠标左键被按下";
//    }
//    if(event->button() == Qt::RightButton)
//    {
//        qDebug() << "鼠标右键被按下";
//    }
//}

//void Widget::mouseReleaseEvent(QMouseEvent *event)
//{
//    if(event->button() == Qt::LeftButton)
//    {
//        qDebug() << "鼠标左键被释放";
//    }
//}

//void Widget::keyPressEvent(QKeyEvent *event)
//{
//    if(event->modifiers() == Qt::ShiftModifier)
//    {
//        if(event->key() == Qt::Key_Q)
//        {
//            qDebug() << "shift + Q 键被按下";
//        }
//    }
//}

